package com.cheejee.goodscenter.controller;

import static com.cheejee.goodscenter.module.response.BaseReponse.*;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cheejee.goodscenter.module.entity.GoodsSpecific;
import com.cheejee.goodscenter.module.response.BaseReponse;
import com.cheejee.goodscenter.service.GoodsSpecificService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author CARRY
 * @Date 2020年11月2日上午7:04:26
 */
@RestController
@RequestMapping("/goods/specific")
@Api(tags = "商品规格")
public class GoodsSpecificController {

	@Resource
	private GoodsSpecificService service;
	
	@GetMapping("/{goodsId}")
	@ApiOperation("查询某商品的规格")
	public Object getSpecificByGoods(@PathVariable Long goodsId) {
		
		return queryOk(service.queryGoodsSpecific(goodsId, null, null, 0, 0));
	}
	
	@PutMapping("/")
	@ApiOperation("新增商品规格")
	public Object addSpecific(@RequestBody List<GoodsSpecific> specific) {
		service.addGoodsSpecific(specific);

		return addOk(specific);
	}
	
	@PutMapping("/change")
	@ApiOperation("修改商品规格")
	public Object changeSpecific(@RequestBody GoodsSpecific specific) {
		service.changeGoodsSpecific(specific);
		
		return changeOk(specific);
	}
	
	@DeleteMapping("/{id}")
	@ApiOperation("修改商品规格")
	public Object deleteSpecific(Long[] id) {
		service.deleteGoodsSpecific(id);
		
		return deleteOk();
	}
}
